class DownloadUrlsController < ApplicationController

  respond_to :html,:js

  def create
    @music =Music.find_by(id: downloadUrl_params[:music_id])

    @download_url = @music.download_urls.build(downloadUrl_params)
    if @download_url.save
      flash[:success] = "下载地址已添加成功"
      redirect_to @music
    else
      flash[:success] = "保存下载地址失败"
      render 'new'
    end

  end

  def destroy
    @downloadUrl = DownloadUrl.find_by(id: params[:id])
    #downloadUrl.destroy

    respond_with @downloadUrl
    #respond_to do |format| # <- 这里
    #
    #    format.html { redirect_to @topic }
    #    format.js # <- 这里
    #
    #
    #end

    #redirect_to downloadUrl.music
  end

  private

  def downloadUrl_params
    params.require(:download_url).permit(:url,:music_id)
  end

end